const fs = require('fs')
const path = require('path')

class FileUtils {
	static createDir(baseDir, ...dirs) {
		if (dirs && dirs.length > 0) {
			let p = path.join(baseDir)
			// 校验父级是否存在
			if (fs.existsSync(p)) {
				const dir = dirs.splice(0, 1)
				p = path.join(p, dir[0])
				if (!fs.existsSync(p)) {
					fs.mkdirSync(p)
				}
				return this.createDir(p, ...dirs)
			} else {
				return new Error(`${p}路径不存在或者创建失败`)
			}
		}
	}
}
module.exports = FileUtils
